package com.glowdayz.glowmee;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class ListEvent extends Fragment implements OnClickListener {
	
	int fragmentIndex = 0;
    public final static int FRAGMENT_ONE = 1;
    public final static int FRAGMENT_TWO = 2;
	
    ImageView nowEvent = null, beforeEvent = null;
    
    DrawerLayout dlDrawerIndex;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        View nowView = inflater.inflate(R.layout.activity_list_event, container, false);
        
        dlDrawerIndex = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
		dlDrawerIndex.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
		
		ImageView backBt = (ImageView) nowView.findViewById(R.id.backBt);
		ImageView okBt = (ImageView) nowView.findViewById(R.id.okBt);
		backBt.setVisibility(View.GONE);
		okBt.setVisibility(View.GONE);
		
		TextView textTitle = (TextView) nowView.findViewById(R.id.textTitle);
		textTitle.setText("이벤트");
		
		nowEvent = (ImageView) nowView.findViewById(R.id.nowEvent);
		beforeEvent = (ImageView) nowView.findViewById(R.id.beforeEvent);
		nowEvent.setOnClickListener(this);
		beforeEvent.setOnClickListener(this);
		
		fragmentIndex = FRAGMENT_ONE;
		fragmentReplace(fragmentIndex);
		
		return nowView;
		
	}
	
	public void fragmentReplace(int reqNewFragmentIndex) {
		Bundle bundle = new Bundle();
		bundle.putInt("PARAM_event", fragmentIndex);
        Fragment newFragment = new EventFm();
        newFragment.setArguments(bundle);
        final FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.ll_fragment, newFragment);
        transaction.commit();
    }
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.nowEvent:
			nowEvent.setImageResource(R.drawable.tap_on_ing);
			beforeEvent.setImageResource(R.drawable.tap_off_ed);
			fragmentIndex = FRAGMENT_ONE;
            fragmentReplace(fragmentIndex);
			break;
		case R.id.beforeEvent:
			nowEvent.setImageResource(R.drawable.tap_off_ing);
			beforeEvent.setImageResource(R.drawable.tap_on_ed);
			fragmentIndex = FRAGMENT_TWO;
            fragmentReplace(fragmentIndex);
			break;
		}
	}
	
}
